package com.didispace;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.didispace.service.hello.HelloService;
import com.google.gson.Gson;

@RestController
public class ConsumerController {

	@Autowired
	Gson gson;
	
    @Autowired
    HelloService helloService;
    @Autowired
    RefactorHelloService refactorHelloService;

    @RequestMapping(value = "/feign-consumer", method = RequestMethod.GET)
    public String helloConsumer() {
        return helloService.hello();
    }

    @RequestMapping(value = "/feign-consumer2", method = RequestMethod.GET)
    public String helloConsumer2() {
        StringBuilder sb = new StringBuilder();
        sb.append(helloService.hello()).append(":  ");
        sb.append(helloService.hello("DIDI")).append(":  ");
        sb.append(gson.toJson(helloService.hello("DIDI", "20"))).append(":  ");

        sb.append(helloService.hello(new User("DIDI", "30"))).append(":  ");
        return sb.toString();
    }

    @RequestMapping(value = "/feign-consumer3", method = RequestMethod.GET)
    public String helloConsumer3() {
        StringBuilder sb = new StringBuilder();
        sb.append(refactorHelloService.hello("MIMI")).append(":  ");
        sb.append(gson.toJson(refactorHelloService.hello("MIMI", "20"))).append(":  ");
        sb.append(refactorHelloService.hello(new User("MIMI", "20"))).append(":  ");
        return sb.toString();
    }

}